<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>个人信息</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui-flex.css"/>
    <!--<link rel="stylesheet" type="text/css" href="../../css/common.css"/>-->
    <style>
        body {
            background: #f3f3f3;
            font-size: 14px;
        }
        .infoUl:after,.infoUl:before{
            border-top:none;
        }
    </style>
</head>
<body>
<div class="contain" id="info-content">
</div>
</body>
<script id="info-template" type="text/x-dot-template">
    <ul class="aui-list-view infoUl" {{?it.userid==myUid}}onclick="openToTwo('modifyInfo_win')"{{?}}>
        <li class="aui-list-view-cell aui-img">
            {{?it.userid==myUid}}
            <div class="aui-arrow-right">
            {{?}}
                <img class="aui-img-object aui-pull-left" src="{{=it.head_portrait}}" {{?it.userid!=myUid}} onclick="showAvatar('{{=it.head_portrait}}');" {{?}}>
                <div class="aui-img-body aui-ellipsis-1">
                    {{=it.nickname}}
                    <p class="aui-ellipsis-1">{{?it.vcompany}}<i class="aui-iconfont aui-icon-vip" style="color:orange;margin:0;padding: 0;"></i><span style="color:orange;">&nbsp;已认证商家</span>{{??}}个人用户{{?}}</p>
                    <!-- <p class="aui-ellipsis-1">账号:峰龙科技公司</p> -->
                </div>
            {{?it.userid==myUid}}
            </div>
            {{?}}
        </li>
    </ul>
    {{?it.vcompany}}
    <ul class="aui-list-view" onclick="go2Shop({{=it.companyInfo.userid}},'../')">
        <li class="aui-list-view-cell aui-img">
            <div class="aui-arrow-right">
                <div class="aui-flex-col">
                    <div class="aui-flex-item-3">店铺</div>
                    <div class="aui-flex-item-9 aui-ellipsis-1" style="color:#000;">{{=it.companyInfo.company}}</div>    
                </div>
            </div>
        </li>
        {{?it.mallItems&&it.mallItems.length}}
        <li class="aui-list-view-cell aui-img aui-flex-col">
            <div class="aui-flex-item-3  aui-flex-row aui-flex-middle ">在售货品</div>
            <div class="aui-flex-item-9 aui-flex-col">
                {{ for(var i in it.mallItems){ }}
                <div class="aui-flex-item-4 aui-padded-0-5">
                    <div class="resized-img" style="background-size:cover;background-image: url({{=it.mallItems[i].thumb}});width: 100%;"></div>
                </div>
                {{ } }}
            </div>
        </li>
        {{?}}
    </ul>
    {{?}}
    {{?it.postPics&&it.postPics.length}}
    <ul class="aui-list-view" onclick="go2Userpost({{=it.userid}},'{{=it.nickname}}',{{=it.relation}})">
        <li class="aui-list-view-cell aui-img aui-flex-col">
            <div class="aui-flex-item-3  aui-flex-row aui-flex-middle ">个人相册</div>
            <div class="aui-flex-item-9">
                <div class="aui-flex-col">
                    {{ for(var i in it.postPics){ }}
                    <div class="aui-flex-item-4 aui-padded-0-5">
                        <div class="resized-img" style="background-size:cover;background-image: url({{=it.postPics[i].url}});width: 100%;"></div>
                    </div>
                    {{ } }}
                </div>
            </div>
        </li>
    </ul>
    {{?}}
    <div class="aui-padded-0-10">
    {{?it.userid==myUid}}
        <div class="aui-btn aui-btn-success aui-btn-block" onclick="openToTwo('modifyInfo_win')">修改资料</div>
        <br />
        {{?it.vcompany}}
        <div class="aui-btn aui-btn-info aui-btn-block"  onclick="go2Shop({{=it.companyInfo.userid}},'../')">进入我的店铺</div>
        {{??}}
        <div class="aui-btn aui-btn-info aui-btn-block " onclick="openToTwo('comAuthentiction_win','../')">认证信息</div>
        {{?}}
    {{??}}
        {{?it.relation==2}}
        <div class="aui-btn aui-btn-success aui-btn-block" onclick="openchat({{=it.userid}},'{{=it.head_portrait}}','{{=it.nickname}}','../')">发送消息</div>
        <br />
        {{??myUid&&it.relation==0}}
        <div class="aui-btn aui-btn-success aui-btn-block" onclick="addFriend(this)" data-userid="{{=it.userid}}">加为好友</div>
        <br />
        {{??myUid&&it.relation==1}}
        <div class="aui-btn aui-btn-default aui-btn-block" onclick="delFriend(this)" data-userid="{{=it.userid}}">已申请好友</div>
        <br />
        {{?}}
        {{?it.vcompany}}
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="go2Shop({{=it.companyInfo.userid}},'../')">进入商家店铺</div>
        <br />
        {{?}}
    {{?}}
    </div>
</script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script type="text/javascript" src="../../script/jquery-1.11.3.js"></script>
<script type="text/javascript">
    var isLock=false,myUid;
    apiready = function () {
        api.parseTapmode();

        getStorageAll();
        myUid=user_id;

        loadData();

        api.addEventListener({
            name: 'modifyInfo'
        }, function (ret, err) {
            if (ret && ret.value) {
                loadData();
            }
        });
    }

    function loadData(){
        var userId=api.pageParam.userid;
        var url='Member/info?userid='+userId+'&username='+user_name;

        ajaxRequest(url, 'get', {}, function (ret, err) {
            if(ret.status==1){
               var tpl = $api.byId('info-template').text;
               var tempFn = doT.template(tpl);
               $('#info-content').show().html(tempFn(ret.msg));

               //css adjust
               $('.resized-img').each(function(){
                    $(this).height($(this).width());
               })

               if(ret.msg.relation==2){
                    api.execScript({
                        name:'my/personInfo_win',
                        script:'showDelfriend()'
                    });
               }

            }else{
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
    }

    //单击加为人脉
    function addFriend(obj) {
         getStorageAll();
         var $obj=$(obj);
         var fuserid=$obj.attr('data-userid');
         ajaxRequest('Friendship/follow?username='+user_name, 'post', {fuserid:fuserid}, function (ret, err) {
            if (ret.status == 1&&(typeof ret.msg !== 'string')) {
                $obj.attr('onclick','javascript:delFriend(this)');
                $obj.removeClass('aui-btn-success').addClass('aui-btn-default');
                $obj.text('已申请好友');
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                })
            }
        })
    }

    function delFriend(obj){
         getStorageAll();
         var $obj=$(obj);
         var fuserid=$obj.attr('data-userid');
         ajaxRequest('Friendship/unfollow?username='+user_name, 'post', {fuserid:fuserid}, function (ret, err) {
            if (ret.status == 1&&(typeof ret.msg !== 'string')) {
                $obj.attr('onclick','javascript:addFriend(this)');
                $obj.removeClass('aui-btn-default').addClass('aui-btn-success');
                $obj.text('加为好友');
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                })
            }
        })
    }

    //跳转到用户动态页
    function go2Userpost(userid, nickname,relation,path) {
        path = path ? path : './';
        api.openWin({
            name: 'userpost_win',
            url: path + 'userpost_win.html',
            pageParam: {
                nickname:nickname,
                userid: userid,
                isFriend:(relation==2||userid==myUid)
            }
        });
    }

    function showAvatar(img){
        api.openWin({
            name: 'photobrowser_win',
            url: '../friend/photobrowser_win.html',
            animation:{
                type:"fade",               
                duration:200
            },
            pageParam:{
                imgList:[img]
            }
        });
    }
</script>
</html>
